#!/bin/bash
# this is the boot-service init script for the device-manager resources
#
# openQRM Enterprise developed by openQRM Enterprise GmbH.
#
# All source code and content (c) Copyright 2014, openQRM Enterprise GmbH unless specifically noted otherwise.
#
# This source code is released under the GNU General Public License version 2, unless otherwise agreed with openQRM Enterprise GmbH.
# The latest version of this license can be found here: src/doc/LICENSE.txt
#
# By using this software, you acknowledge having read this license and agree to be bound thereby.
#
#           http://openqrm-enterprise.com
#
# Copyright 2014, openQRM Enterprise GmbH <info@openqrm-enterprise.com>
#

OPENQRM_SERVER_BASE_DIR=$(pushd $(dirname $0)/../../../../.. > /dev/null; echo $PWD; popd > /dev/null)
# for including the package functions
export OPENQRM_SOURCE_DIR="$OPENQRM_SERVER_BASE_DIR/openqrm/"
. $OPENQRM_SERVER_BASE_DIR/openqrm/include/openqrm-functions
. $OPENQRM_SERVER_BASE_DIR/openqrm/include/openqrm-package-functions
. $OPENQRM_SERVER_BASE_DIR/openqrm/plugins/device-manager/include/openqrm-plugin-device-manager-functions
. $OPENQRM_RESOURCE_PARAMETER_FILE
OPENQRM_SERVER_IP=$resource_openqrmserver

# do not run on idle resources
if [ "$resource_image" == "idle" ]; then
	exit 0
fi

# also do not run before the real init of the rootfs
# if we have this file /etc/initrd-devices.conf we are still in the initrd
if [ -f /etc/initrd-devices.conf ]; then

	# TODO: add your commands to run in the initrd-stage on a managed system (network-deployment only)

	exit 0
fi


function device_manager_start() {
	echo "Starting the openQRM device-manager-plugin"
	device_manager_stop 1>/dev/null 2>&1
}


function device_manager_stop() {
	echo "Stopping the openQRM device-manager-plugin"
}





case "$1" in
	start)
		device_manager_start
		;;
	stop)
		device_manager_stop
		;;
	restart)
		device_manager_stop
		sleep 1
		device_manager_start
		;;
	*)
		echo "Usage: $0 {start|stop|restart}"
		exit 1

esac
exit $?













